package com.jzr.board.ui

import android.content.Intent
import android.view.View
import androidx.fragment.app.Fragment
import com.google.android.material.tabs.TabLayout
import com.jzr.board.R
import com.jzr.board.base.BaseActivity
import com.jzr.board.base.BaseFragmentPageAdapter
import com.jzr.board.service.KeepLiveService
import com.jzr.board.ui.fragment.ecg.EcgFragment
import com.jzr.board.ui.fragment.main.InfusionFragment
import com.jzr.board.ui.fragment.main.NurseSchedulFragment
import com.jzr.board.ui.fragment.main.PatientListFragment
import com.jzr.board.ui.fragment.main.TodyWorkFragment
import com.jzr.board.utils.AreaClickListener
import com.jzr.board.utils.PreferUtil
import kotlinx.android.synthetic.main.actionbar_root_layout.*
import kotlinx.android.synthetic.main.activity_main.*
import java.util.*

class MainActivity : BaseActivity() {


    private var myAdapter: BaseFragmentPageAdapter? = null
    private val mTitleList = ArrayList<String>()
    private val mFragments: ArrayList<Fragment> = ArrayList<Fragment>()

    override fun getLayoutId(): Int {
       return R.layout.activity_main
    }

    override fun attachView() {

    }

    override fun detachView() {

    }

    override fun initView() {

        startService()
        ivRight.visibility = View.INVISIBLE
        tvTitle.visibility = View.VISIBLE
        tvTitle.text = PreferUtil.getInstance().deptName

        mTitleList.add("今日工作")
        mTitleList.add("病床信息")
//        mTitleList.add("护理培训")
         mTitleList.add("护士排班")
        mTitleList.add("输液监控")
        mTitleList.add("心电图表")
//        mTitleList.add("系统设置")

        mFragments.add(TodyWorkFragment.newInstance()!!)
        mFragments.add(PatientListFragment.newInstance()!!)
        mFragments.add(NurseSchedulFragment.newInstance()!!)
        mFragments.add(InfusionFragment.newInstance()!!)
        mFragments.add(EcgFragment.newInstance()!!)

        myAdapter = BaseFragmentPageAdapter(supportFragmentManager, mFragments, mTitleList)
        vp.adapter = myAdapter
        myAdapter?.notifyDataSetChanged()
        tabLayout.setupWithViewPager(vp)

        tabLayout.tabGravity = TabLayout.GRAVITY_FILL
        tabLayout.tabMode = TabLayout.MODE_SCROLLABLE

        ivBack.setOnClickListener(AreaClickListener(5, 500, AreaClickListener.ClickEvent {
            startActivityIn(
                Intent(this@MainActivity, SystemSettingActivity::class.java),
                this@MainActivity
            )
        }))
    }

    private fun startService() {
        val intent = Intent(this@MainActivity, KeepLiveService::class.java)
        startService(intent)
    }

}
